import {createRouter, createWebHistory} from "vue-router";

const routes = [
    {
        path: "",
        component: () => import("../views/homeview.vue"),
        name: "home",
        children: [
            {
                path: "",
                component: () => import("../views/shouye.vue"),
                name: "shouye",
            },
            {
                path: "query",
                component: () => import("../views/Wuliuquery.vue"),
                name: "Wuliuquery",
            }, {
                path: "/business/shuangqing/air",
                component: () => import("@/views/companyServer/sqhszx/Sqky.vue"),
                name: "companyServer",
            }, {
                path: "/about",
                component: () => import("../views/companyIntroduction.vue"),
                name: "companyIntroduction",
            }, {
                path: "/contant",
                component: () => import("../views/connectUS.vue"),
                name: "contant",
            }, {
                path: "/case",
                component: () => import("../views/JdAl.vue"),
                name: "case",
            }, {
                path: "/new",
                component: () => import("../views/news.vue"),
                name: "new",
            }, {
                path: "jdalxq",
                component: () => import("../views/Jdalxq.vue"),
                name: "JdAlxq",
            }, {
                path: "newsxq",
                component: () => import("../views/newsxq.vue"),
                name: "Newsxq",

            }, {
                path: "/business/shuangqing/automobile-express-line",
                component: () => import("@/views/companyServer/sqhszx/Sqqykx.vue"),
                name: "sqqykx",
            }, {
                path: "/business/shuangqing/automobile-generally-fast",
                component: () => import("@/views/companyServer/sqhszx/Sqqypk.vue"),
                name: "sqqypk",
            }, {
                path: "/business/shuangqing/railway",
                component: () => import("@/views/companyServer/sqhszx/Sqtlzx.vue"),
                name: "sqtlzx",
            }, {
                path: "/business/shuangqing/category",
                component: () => import("@/views/companyServer/sqhszx/Sqdypl.vue"),
                name: "Sqdypl",
            }, {
                path: "/business/shuangqing/russia",
                component: () => import("@/views/companyServer/sqhszx/Sqelsydqsmzx.vue"),
                name: "Sqelsydqsmzx",
            }, {
                path: "/business/baiguan/scattered",
                component: () => import("@/views/companyServer/bgzx/qysp.vue"),
                name: "qysp"
            },{
                path: "/business/baiguan/whole",
                component: () => import("@/views/companyServer/bgzx/qyzc.vue"),
                name: "qyzc"
            }, {
                path: "/business/baiguan/railway-container",
                component: () => import("@/views/companyServer/bgzx/tlpg.vue"),
                name: "tlpg"
            }, {
                path: "/business/baiguan/empty-transport",
                component: () => import("@/views/companyServer/bgzx/kysp.vue"),
                name: "kysp"
            },{
                path: "/business/transportation/transport-automobile",
                component: () => import("@/views/companyServer/cyszx/qyzc.vue"),
                name: "qyzc2"
            }, {
                path: "/business/transportation/transport-whole-vehicle",
                component: () => import("@/views/companyServer/cyszx/tlzg.vue"),
                name: "tlzg"
            }, {
                path: "/business/transportation/transport-scattered",
                component: () => import("@/views/companyServer/cyszx/tlsp.vue"),
                name: "tlsp"
            }, {
                path: "/business/transportation/transport-air",
                component: () => import("@/views/companyServer/cyszx/ky.vue"),
                name: "dypl"
            }, {
                path: "/business/customs/customs",
                component: () => import("@/views/companyServer/dlqg/dlqg.vue"),
                name: "dlqg"
            }
        ]

    },
];
const router = createRouter({
    history: createWebHistory(),
    routes,
    scrollBehavior(to, from, savedPosition) {
        // 在这里判断特定的路由
        if (to.name === 'case' || to.name === 'new') {
            // 对于指定的路由，使用保存的位置
            if (savedPosition) {
                return savedPosition;
            } else {
                return { top: 0 }; // 如果没有保存位置，则返回顶部
            }
        } else {
            // 对于其他路由，返回到固定位置（比如顶部）
            return { top: 0 };
        }
        console.log('Navigating to:', to.name);
        console.log('Saved Position:', savedPosition);
    }
});

export default router;
